package com.tech.thread.sync;

import jdk.nashorn.internal.ir.ReturnNode;
import sun.security.jca.GetInstance;

import java.util.concurrent.locks.Lock;

/**
 * @Description: 模拟静态内部类的方式实现线程安全的单例
 * @Author: zl
 * @Date: 2019/7/23 17:27
 */
public class SingletonDemo01 {
    public SingletonDemo01() {
    }

    static class InnerClass {
        private static final SingletonDemo01 instance = new SingletonDemo01();
    }

    public static SingletonDemo01 getInstance() {
        return InnerClass.instance;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    SingletonDemo01 demo = null;
                    demo = SingletonDemo01.getInstance();
                    System.out.println(demo);
                }
            }).start();
        }
    }

}
